﻿
 function toPage(pageNo,dName){
         $.postBack({_method_:"toPage","pageNo":pageNo}, function(data) {
            loadPage2(eval(data.Result[1]),dName);
            toTbl(eval(data.Result[0]));
        });  
     
     }    
     
     function bef2(dName){
      var num=$("#pNo").val();
      if(num==1||num==0)return;
      else
        toPage2((num - 1),dName)
     }
     function nex2(dName){var count=$("#pCount").val();var num=$("#pNo").val();
         if(num==count||count==0)return;else num=num-1 + 2;
        toPage2(num,dName);
     }
     function las2(dName) { toPage2($("#pCount").val(), dName) }

function loadPage2(pager,dName){
 $("#"+dName).html("");
    var ymStr="&nbsp;";
    var ym=pager.PageNo;
    var star=1;
    var end=ym+2;
    var count=pager.PageCount;
    if(ym>=3){ star=ym-2;}
    if(end>count){
        end=count;
    }
    for(var i=star;i<=end;i++){
        if(i==ym){
            ymStr+="<font color='red'>"+i+"</font>&nbsp;";
        }else
        ymStr+="<a onclick=\"toPage2("+i+",'"+dName+"')\" class='ppBtn'>"+i+"</a>&nbsp;";
    }

        $("#"+dName).html("<table width='100%'><tr><td align='right'>当前第"+pager.PageNo+"/"
        +"<input type='hidden' id='pCount' value='"+pager.PageCount+"' />"+pager.PageCount+"页 共"+pager.RecordCount+"条记录 每页"+pager.PageSize+"条</td><td align='center'>"
        +"<a  id='first' class='ppBtn' onclick=\"toPage2(1,'"+dName+"')\">首页</a>&nbsp;"
        +"<a id='before' class='ppBtn' onclick=\"bef2('"+dName+"')\">上一页</a>&nbsp;"
        +"<input type='hidden' id='pNo' value='"+pager.PageNo+"' />"+ymStr
        +"<a  id='next' class='ppBtn' onclick=\"nex2('"+dName+"')\">下一页</a>&nbsp;"
        +"<a  id='last' class='ppBtn' onclick=\"las2('"+dName+"')\">尾页</a>"
        +"</td></tr></table>");
        
        //var count=$("#pCount").val();
        if(pager.PageNo==count||count==0){
           $("#next").attr("className","unDo");
            $("#last").attr("className","unDo");
        }
        if(pager.PageNo==1||count==0){
         $("#before").attr("className","unDo");
            $("#first").attr("className","unDo");
        }
     
     }

     function createPager2(pageIndex, total, spanInterval, pageSize)
    {
       //将当前页索引转为int类型                        
            var intPageIndex = parseInt(pageIndex);
            var pageSize = pageSize;
            //创建分页
            //将总记录数结果 得到 总页码数
            var pageS = total;
            if (pageS % pageSize == 0) pageS = pageS / pageSize;
            else pageS = parseInt(total / pageSize) + 1;
            var $pager = $("#pager2");            

            //清楚分页div中的内容                        
            $("#pager2 span").remove();
            $("#pager2 a").remove();



            //添加第一页
            if (intPageIndex == 1)
                $pager.append("<span>首页</span>");
            else {
                var first = $("<a href='javascript:void(0)' first='" + 1 + "'>首页</a>").click(function () {
                    PageClick2($(this).attr('first'), total, spanInterval);
                    return false;
                });
                $pager.append(first);
            }
            //添加上一页
            if (intPageIndex == 1)
                $pager.append("<span>上一页</span>");
            else {
                var pre = $("<a href='javascript:void(0)' pre='" + (intPageIndex - 1) + "'>上一页</a>").click(function () {
                    PageClick2($(this).attr('pre'), total, spanInterval);
                    return false;
                });
                $pager.append(pre);
            }

            //设置分页的格式  这里可以根据需求完成自己想要的结果
            var interval = parseInt(spanInterval); //设置间隔
            var start = Math.max(1, intPageIndex - interval); //设置起始页
            var end = Math.min(intPageIndex + interval, pageS)//设置末页

            if (intPageIndex < interval + 1) {
                end = (2 * interval + 1) > pageS ? pageS : (2 * interval + 1);
            }
            if ((intPageIndex + interval) > pageS) {
                start = (pageS - 2 * interval) < 1 ? 1 : (pageS - 2 * interval);
            }


            //生成页码                        
            for (var j = start; j < end + 1; j++) {
                if (j == intPageIndex) {
                    var spanSelectd = $("<span class='fenyered'>" + j + "</span>");
                    $pager.append(spanSelectd);
                    //$pager.append("<span>&nbsp;</span>");
                }
                //if                             
                else {
                    var a = $("<a href='javascript:void(0)'>" + j + "</a>").click(function () {
                        PageClick2($(this).text(), total, spanInterval);
                        return false;
                    });
                    $pager.append(a);
                    //$pager.append("<span>&nbsp;</span>");                           
                } //else                        
            } //for                  
            //上一页                        
            if (intPageIndex >= pageS) {
                $pager.append("<span>下一页</span>");
            } else {
                var next = $("<a href='javascript:void(0)' next='" + (intPageIndex + 1) + "'>下一页</a>").click(function () {
                    PageClick2($(this).attr("next"), total, spanInterval);
                    return false;
                });
                $pager.append(next);
            }
            //最后一页                        
            if (intPageIndex >= pageS) {
                $pager.append("<span>尾页</span>");
            }
            else {
                var last = $("<a href='javascript:void(0)' last='" + pageS + "'>尾页</a>").click(function () {
                    PageClick2($(this).attr("last"), total, spanInterval);
                    return false;
                });
                $pager.append(last);
            }
            $pager.append("<span>当前第" + pageIndex + "/" + pageS + "页 共" + total + "条记录 每页" + pageSize + "条</span>");

        }